<?php

namespace Robot\Controller;

class CustomerController extends AdminbaseController {

    function _initialize() {
        parent::_initialize();
        $this->currentModel = D("Customer");
    }

    //首页
    public function index() {

        $_REQUEST["is_robot"] = C("DEFAULT_YN.YES");
        $requestMap = $this->convertRequestToMap();

        //分页
        $count = $this->currentModel->getListCount($requestMap);
        $page = $this->page($count, C("DEFAULT_PAGE_SIZE"));

        //获取customer列表
        $userList = $this->currentModel->queryForList($page, $requestMap);

        $this->assign("statusEnum", C("DEFAULT_YN"));
        $this->assign('userList', $userList);
        $this->assign("page", $page->show('Robot', $this->parameter));
        $this->display();

    }

    public function addPost() {

        $nickname = $_REQUEST["nickname"];
        $image = $_REQUEST["image"];

        $data["nickname"] = $nickname;
        $data["headimgurl"] = $image;
        $data["is_robot"] = C("DEFAULT_YN.YES");
        $data["create_time"] = getCurrentDate();
        $data["subscribe"] = 0;

        D("Customer")->add($data);

        $this->success("添加成功", U("customer/index"));

    }

    public function editPost() {

        $id = $_REQUEST["id"];
        $nickname = $_REQUEST["nickname"];
        $image = $_REQUEST["image"];

        $data = D("Customer")->queryById($id);

        $data["nickname"] = $nickname;
        $data["headimgurl"] = $image;

        D("Customer")->updateInfo($data);

        $this->success("编辑成功", U("customer/index"));

    }
}